package com.hncc.dms.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.hncc.dms.domain.DmsDiseCatalog;
import com.hncc.dms.service.IDmsDiseCatalogService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import javax.annotation.Resource;

/**
 * 诊断目录管理Controller
 * 
 * @author ruoyi
 * @date 2020-08-14
 */
@RestController
@RequestMapping("/dms/dise_catalog")
@Api(tags = "诊断目录管理接口")
public class DmsDiseCatalogController extends BaseController
{
    @Resource
    private IDmsDiseCatalogService dmsDiseCatalogService;

    /**
     * 查询诊断目录管理列表
     */
    @ApiOperation(value = "条件分页查询诊断目录管理",httpMethod = "GET")
    @PreAuthorize("@ss.hasPermi('dms:dise_catalog:list')")
    @GetMapping("/list")
    public TableDataInfo list(DmsDiseCatalog dmsDiseCatalog)
    {
        startPage();
        List<DmsDiseCatalog> list = dmsDiseCatalogService.selectDmsDiseCatalogList(dmsDiseCatalog);
        return getDataTable(list);
    }

    /**
     * 导出诊断目录管理列表
     */
    @PreAuthorize("@ss.hasPermi('dms:dise_catalog:export')")
    @Log(title = "诊断目录管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(DmsDiseCatalog dmsDiseCatalog)
    {
        List<DmsDiseCatalog> list = dmsDiseCatalogService.selectDmsDiseCatalogList(dmsDiseCatalog);
        ExcelUtil<DmsDiseCatalog> util = new ExcelUtil<DmsDiseCatalog>(DmsDiseCatalog.class);
        return util.exportExcel(list, "dise_catalog");
    }

    /**
     * 获取诊断目录管理详细信息
     */
    @ApiOperation(value = "根据id获取诊断目录管理详细信息",httpMethod = "GET",
            notes = "根据id查询诊断目录管理")
    @ApiImplicitParam(paramType = "path",name = "id",value = "诊断目录管理id",dataType = "Long",required = true)
    @PreAuthorize("@ss.hasPermi('dms:dise_catalog:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(dmsDiseCatalogService.selectDmsDiseCatalogById(id));
    }

    /**
     * 新增诊断目录管理
     */
    @ApiOperation(value = "新增",httpMethod = "POST", notes = "新增诊断目录管理")
    @ApiImplicitParam(name = "dmsDiseCatalog", value = "新增诊断目录管理", dataType = "DmsDiseCatalog")
    @PreAuthorize("@ss.hasPermi('dms:dise_catalog:add')")
    @Log(title = "诊断目录管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DmsDiseCatalog dmsDiseCatalog)
    {
        return toAjax(dmsDiseCatalogService.insertDmsDiseCatalog(dmsDiseCatalog));
    }

    /**
     * 修改诊断目录管理
     */
    @ApiOperation(value = "修改", httpMethod = "PUT", notes = "修改诊断目录管理")
    @ApiImplicitParam(name = "dmsDiseCatalog", value = "修改诊断目录管理", dataType = "DmsDiseCatalog")
    @PreAuthorize("@ss.hasPermi('dms:dise_catalog:edit')")
    @Log(title = "诊断目录管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DmsDiseCatalog dmsDiseCatalog)
    {
        return toAjax(dmsDiseCatalogService.updateDmsDiseCatalog(dmsDiseCatalog));
    }

    /**
     * 删除诊断目录管理
     */
    @ApiOperation(value = "批量删除", httpMethod = "DELETE", notes = "根据ids删除诊断目录管理")
    @ApiImplicitParam(paramType = "path",name = "ids",value = "诊断目录管理id",dataType = "Long[]",required = true)
    @PreAuthorize("@ss.hasPermi('dms:dise_catalog:remove')")
    @Log(title = "诊断目录管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{id}")
    public AjaxResult remove(@PathVariable Long id)
    {
        int result=dmsDiseCatalogService.deleteDmsDiseCatalogById(id);
        if (result==-1){
            return AjaxResult.error("该诊断目录下存在疾病，不能删除");
        }
        return toAjax(result);
    }
}
